\begin{verbatim}
function CoincidenceDiscriminant(S)
    // INPUT: A sequence of 2-character strings, produced 
    // as decimation of transposition ciphertext, or of 
    // adjacent characters in some sample plaintext.
    // OUTPUT: A measure of the difference of probability 
    // of association of two characters, relative to their 
    // independent probabilities.
    C2S := CodeToString;
    AA := [ C2S(64+i)*C2S(64+j) : i, j in [1..26] ];
    FD1 := FrequencyDistribution(&*[ s[1] : s in S ]);
    FD2 := FrequencyDistribution(&*[ s[2] : s in S ]);
    N := #S;
    F2D := [ RealField() | 0 : i in [1..26^2] ];
    for s in S do
        F2D[Index(AA,s)] +:= 1/N;
    end for;
    return &+[ (F2D[i+26*(j-1)]-FD1[i]*FD2[j])^2 : i,j in [1..26] ];
end function;
\end{verbatim}
